/****************************************************************************
 *  _____       ______  _____
 * |_   _|     |  ____|/ ____|
 *   | |  _ __ | |__  | (___    Institute of Embedded Systems
 *   | | | '_ \|  __|  \___ \   Zürcher Hochschule für Angewandte
 *  _| |_| | | | |____ ____) |  Wissenschaften
 * |_____|_| |_|______|_____/   8401 Winterthur, Switzerland
 *
 ****************************************************************************
 *
 * @version $Rev: 212 $
 * @author  $Author: bacr $
 * @date    $Date: 2014-01-10 14:09:50 +0100 (ven., 10 janv. 2014) $
 *
 ***************************************************************************/

#ifndef __PTP2_SHADOW_TABLE_H__
#define __PTP2_SHADOW_TABLE_H__

typedef struct ptp2_shadow_table_t      ptp2_shadow_table_t;

#include "hcpp_config.h"
#include "hcpp/ptp2_node_table.h"

struct ptp2_shadow_table_t {
    object_t                        obj;

    uint16_t                        size;                                               /**< actual size */
    ptp2_node_address_t             address_table[PTP2_NODE_TABLE_MAX_ENTRIES];         /**< array of node addresses, unsorted, shared index */
    ptp2_slave_t                    slave_table[PTP2_NODE_TABLE_MAX_ENTRIES];           /**< array of slaves, unsorted, shared index */
};

bool ptp2_shadow_table_init(ptp2_shadow_table_t *this);
void ptp2_shadow_table_copy(ptp2_shadow_table_t *this, ptp2_node_table_t *node_table);

static inline uint16_t
ptp2_shadow_table_get_size(ptp2_shadow_table_t *this)
{
    return this->size;
}

/**
 *
 */
static inline bool
ptp2_shadow_table_get_slave_by_index(ptp2_shadow_table_t *this, uint16_t idx, ptp2_slave_t **slave_found)
{
    if (idx >= this->size) {
        (*slave_found) = NULL;
        return false;
    }

    (*slave_found) = &(this->slave_table[idx]);

    return true;
}

#endif

